/*
 * fsm.h
 *
 *  Created on: 2013-6-29
 *      Author: yangyang
 */
#include "ses_common.h"
#ifndef FSM_H_
#define FSM_H_
/*TYPEDEF************************************************************/
typedef struct Event Event;
typedef struct Fsm Fsm;
/* a state is represented by a function pointer */
typedef void (*State)(Fsm *, const Event *);
/* base type for events*/
struct Event {
uint8_t signal;
};
/* base type for state machine*/
struct Fsm {
State state; //current state
uint8_t alarmSet; // is alarm enabled ?
uint32_t timeSet; // temporary buffer for time
};

/*FUNCITON************************************************************/
/* dispatches events to state machine, called in application*/
inline static void fsm_dispatch(Fsm* fsm, const Event* event) {
fsm->state(fsm, event);
};
/* sets and calls initial state of state machine */
inline static void fsm_init(Fsm* fsm, State init) {
fsm->state = init;
fsm_dispatch(fsm, NULL);
};

#endif /* FSM_H_ */
